﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SHKF.B2C.BaseHosted;
using SHKF.B2C.BLL.WorkingCenter;
using SHKF.B2C.Hosted;
using SHKF.B2C.Model.Dto;
using SHKF.B2C.Model.Dto.WorkingCenter;
using SHKF.B2C.Model.Entity.WorkingCenter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SHKF.B2C.Mannage.Service.Controllers
{
    /// <summary>
    /// 分仓列表
    /// </summary>
    [Route("[controller]")]
    [ApiController]
    public class DataWarehousInfoController : BaseController
    {
        private readonly DataWarehousInfoBLL dataWarehousInfoBLL;

        public DataWarehousInfoController(DataWarehousInfoBLL dataWarehousInfoBLL,
           ILogger<DataWarehousInfoController> logger) : base(logger)
        {
            this.dataWarehousInfoBLL = dataWarehousInfoBLL;
        }
          
        [HttpPost("Save")]
        public DataWarehousInfoDto Save(DataWarehousInfoEntity info)
        {
            DataWarehousInfoDto dto = new DataWarehousInfoDto();
            try
            {
                dto.data = this.dataWarehousInfoBLL.Save(info);
            }
            catch (Exception ex)
            {
                dto = new DataWarehousInfoDto();
                dto.SetException(ex);
                base.WriteException("DataWarehousInfo=>Save", ex);
            }

            return dto;
        }

        [HttpGet("Delete")]
        public DataDto Delete(int SN)
        {
            DataDto dto = new DataDto();
            try
            {
                int iResult = this.dataWarehousInfoBLL.Delete(SN);
                if (iResult == 0)
                {
                    dto.error = new Error()
                    {
                        code = -1,
                        msg = "成功行数为0"
                    };
                }
            }
            catch (Exception ex)
            {
                dto = new DataDto();
                dto.SetException(ex);
                base.WriteException("DataWarehousInfo>>Save", ex);
            }

            return dto;
        }

        [HttpGet("List")]
        public DataWarehousInfoListDto List(string keyword)
        {
            DataWarehousInfoListDto dto = new DataWarehousInfoListDto();
            try
            {
                dto.data = this.dataWarehousInfoBLL.Query(keyword);
            }
            catch (Exception ex)
            {
                dto = new DataWarehousInfoListDto();
                dto.SetException(ex);
                base.WriteException("DataWarehousInfo>>List", ex);
            }

            return dto;

        }
    }
}
